<?

if(!defined('DIR_VSMAIL'))
	define('DIR_VSMAIL', dirname(__FILE__).DIR_SEP);

require_once(DIR_VSMAIL."vsmailaccount.php");

class VsMailHeader {

	$_account = NULL;

	//Header Properties
	private $_id = 0;
	private $_subject = '';
	private $_addrTo = '';
	private $_addrFrom = '';
	private $_date = '';
	private $_read = FALSE;

	function id() { return $this->_id; }
	function subject() { return $this->_subject; }
	function addrTo() { return $this->_addrTo; }
	function addrFrom() { return $this->_addrFrom; }
	function date() { return $this->_date; }
	function read() { return $this->_read; }
	function unread() { return !$this->_read; }
	//==================================================================================

	function makeHeaders($account) {
		$listHeaders = array();
		$headers = imap_headers($account->imap());

		foreach($headers as $h) {
			$vsh = &new self::__construct($account);

			$vsh->_subject = $h->_subject;
			$vsh->_addrTo = $h->to;
			$vsh->_addrFrom = $h->from;
			$vsh->_date = $h->date;
			$vsh->_read = (($h->Recent=='N') || ($h->Unseen=='U')) ? FALSE : TRUE;

			array_push($listHeaders, $vsh);
		}

		return $listHeaders;
	}
	//==================================================================================

	private function __construct($account = NULL) {
		if($account) {
			$this->_account = $account;
		}
		else {
			$this->_account = VsMailAccount::Instance();
		}
	}
	//=====================================================================

};

?>
